<template>
	<view v-show="!isSortType" :style="{padding:'0 '+prConfig+'px'}">
		<view class="index-product-wrapper" :class="bgStyle===0?'':'borderRadius15'"
			:style="{ marginTop: mbConfig*2 + 'rpx', background: themeColor }" v-if="tempArr.length">
			<!-- 单列 -->
			<block v-if="itemStyle == 0">
				<view class="list-box listA" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
					<view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr"
						:key="index" @click="goDetail(item)" style="padding-bottom: 10rpx;box-size: border-box;
						border-bottom: 1px solid lightgrey;">
						<view class="pictrue">
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '1'">{{$t(`秒杀`)}}</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '2'">{{$t(`砍价`)}}</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '3'">{{$t(`拼团`)}}</span>
							<image :src="item.image" mode=""></image>
						</view>
						<view class="text-info"
							style="display: flex; flex-direction: column; justify-content: space-between;">
							<view>
								<view class="title line2" v-if="titleShow">{{ item.store_name }}</view>
								<view class="old-price" v-if="opriceShow">
									{{$t(`￥`)}}{{ item.ot_price }}
								</view>
							</view>
							<view class="price" :style="'color:'+fontColor">
								<view v-if="priceShow">
									<text>{{$t(`￥`)}}</text>
									{{ item.price }}
								</view>
								<view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor"
									:class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">{{$t(`券`)}}</view>
							</view>
						</view>
					</view>
				</view>
			</block>
			<!-- 两列 -->
			<block v-if="itemStyle == 1">
				<view class="list-box listC" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
					<view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr"
						:key="index" @click="goDetail(item)" style="padding-bottom: 10rpx;box-size: border-box;
						border-bottom: 1px solid lightgrey;">
						<view class="pictrue">
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '1'">{{$t(`秒杀`)}}</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '2'">{{$t(`砍价`)}}</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '3'">{{$t(`拼团`)}}</span>
							<image :src="item.image" mode="aspectFit">
						</view>
						<view class="text-info">
							<view class="title line1" v-if="titleShow">{{ item.store_name }}</view>
							<view class="old-price" v-if="opriceShow">
								{{$t(`￥`)}}{{ item.ot_price }}
							</view>
							<view class="price" :style="'color:'+fontColor">
								<view v-if="priceShow">
									{{$t(`￥`)}}
									{{ item.price }}
								</view>
								<view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor"
									:class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">{{$t(`券`)}}</view>
							</view>
						</view>
					</view>
				</view>
			</block>
			<!-- 三列 -->
			<block v-if="itemStyle == 2">
				<view class="list-box listB" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
					<view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr"
						:key="index" @click="goDetail(item)" style="padding-bottom: 10rpx;box-size: border-box;
						border-bottom: 1px solid lightgrey;">
						<view class="pictrue">
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '1'">{{$t(`秒杀`)}}</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '2'">{{$t(`砍价`)}}</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '3'">{{$t(`拼团`)}}</span>
							<image :src="item.image" mode="aspectFit"></image>
						</view>
						<view class="text-info"
							style="display: flex; flex-direction: column; justify-content: space-between;">
							<view>
								<view class="title line1" v-if="titleShow">{{ item.store_name }}</view>
								<view class="old-price" v-if="opriceShow">
									{{$t(`￥`)}}{{ item.ot_price }}
								</view>
							</view>
							<view class="price" :style="'color:'+fontColor">
								<view v-if="priceShow">
									<text>{{$t(`￥`)}}</text>
									{{ item.price }}
								</view>
								<view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor"
									:class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">{{$t(`券`)}}</view>
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		<!-- 大图 -->
		<block v-if="itemStyle == 3 && tempArr.length" :style="{ marginTop: '24rpx' }">
			<view class="listBig" :class="bgStyle===0?'':'borderRadius15'" :style="{ background: themeColor }">
				<view class="itemBig" :class="conStyle?'borderRadius15':''" v-for="(item,index) in tempArr" :key="index"
					@click="goDetail(item)" style="padding-bottom: 10rpx;box-size: border-box;
						">
					<view class="img-box">
						<span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor"
							v-if="item.activity && item.activity.type === '1'">{{$t(`秒杀`)}}</span>
						<span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor"
							v-if="item.activity && item.activity.type === '2'">{{$t(`砍价`)}}</span>
						<span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor"
							v-if="item.activity && item.activity.type === '3'">{{$t(`拼团`)}}</span>
						<image :src="item.recommend_image" mode="" v-if="item.recommend_image"></image>
						<image :src="item.image" mode="" v-else></image>
					</view>
					<view class="flex" style="justify-content: space-between;align-items: flex-end;margin-top: 40rpx;">
						<view class="price" style="
font-size: 28rpx;
font-family: Source Han Sans CN-Medium, Source Han Sans CN;
font-weight: 500;
color: #FF0A23;
line-height: 33rpx;">
							<span v-if="priceShow" style="font-weight: Bold;">{{$t(`￥`)}}
								<span class="num" style="
font-size: 48rpx;
font-family: Source Han Sans CN-Medium, Source Han Sans CN;
font-weight: Bold;
color: #FF0A23;
line-height: 56rpx;">{{item.price.split('.')[0]}}.</span>
								<span class="num" style="font-weight: Bold;">{{item.price.split('.')[1]}}</span>
							</span>
						</view>
						<view class="price" style="
font-size: 28rpx;
font-family: Source Han Sans CN-Regular, Source Han Sans CN;
font-weight: 400;
color: #666666;
line-height: 33rpx;">
							<text style="
font-size: 28rpx;
font-family: Source Han Sans CN-Regular, Source Han Sans CN;
font-weight: 400;
color: #666666;
line-height: 33rpx;">销量{{item.sales}}</text>
						</view>
					</view>
					<view class="">
						<view class="name line2">
							<span class="coupon" :style="'border:1px solid '+labelColor+';color:'+labelColor"
								v-if="item.checkCoupon && couponShow">{{$t(`券`)}}</span>
							<span v-if="titleShow" style="
font-size: 36rpx;
font-family: Source Han Sans CN-Regular, Source Han Sans CN;
font-weight: 400;
color: #333333;
line-height: 42rpx;letter-spacing: calc(750rpx * 4%);">{{item.store_name}}</span>
						</view>
					</view>

					<!-- 购买 -->
					<view class="flex" style="justify-content: space-between;margin-top: 20rpx;margin-bottom: 30rpx;"
						@click.stop="stop">
						<view class="flex"
							style="width: 300rpx;justify-content: space-between;padding-left: 20rpx;box-sizing: border-box;">
							<view class="flex" style="flex-direction: column;align-items: center;" @click="goCustomer">
								<image src="../../../users/static/kefu.png" mode="aspectFit"
									style="width: 32rpx;height: 32rpx;"></image>
								<text style="
font-size: 24rpx;
font-family: Source Han Sans CN-Regular, Source Han Sans CN;
font-weight: 400;
color: #666666;
line-height: 28rpx;">客服</text>
							</view>
							<view class="flex" style="flex-direction: column;align-items: center;"
							@click="goUrl('/pages/goods/goods_comment_list/index?product_id='+item.id)">
								<image src="../../../users/static/pingjia.png" mode="aspectFit"
									style="width: 32rpx;height: 32rpx;"></image>
								<text style="
font-size: 24rpx;
font-family: Source Han Sans CN-Regular, Source Han Sans CN;
font-weight: 400;
color: #666666;
line-height: 28rpx;">评论</text>
							</view>
							<view class="flex" style="flex-direction: column;align-items: center;"
								@click="listenerActionSheet(item)">
								<image src="../../../users/static/share.png" mode="widthFix"
									style="width: 32rpx;height: 32rpx;overflow: unset;"></image>
								<text style="margin-top: 6rpx;
font-size: 24rpx;
font-family: Source Han Sans CN-Regular, Source Han Sans CN;
font-weight: 400;
color: #666666;
line-height: 28rpx;">分享</text>
							</view>
						</view>
						<view class="" @click="goDetail(item)" style="position: relative;width: 350rpx;right: 20rpx;">
							<view class="" style="display: flex;font-size: 20rpx;background-color:#F9DDDD;
							color: #FF0A23;height: 72rpx;line-height: 72rpx;border-radius: 36rpx 0 0 36rpx;
							padding: 0 70rpx 0 20rpx;box-sizing: border-box;position: absolute;right: 80rpx;
font-size: 20rpx;
font-family: PingFang SC-Medium, PingFang SC;
font-weight: 500;
color: #FF0A23;">
								赠
								<text style="font-size: 28rpx;font-weight: Bold;">{{item.ym_count.split('.')[0]}}.
								<text style="font-size: 24rpx;">{{item.ym_count.split('.')[1]}}</text></text>
								易米
							</view>
							<image style="width: 146rpx;height: 72rpx;position: absolute;right: 0;"
								src="../../../../static/images/buy.png"></image>
						</view>
					</view>
				</view>
			</view>
		</block>
		<!-- 分享按钮 -->
		<view class="generate-posters acea-row row-middle" :class="posters ? 'on' : ''">
			<!-- #ifndef MP -->
			<button class="item" hover-class="none" v-if="weixinStatus === true" @click="H5ShareBox = true">
				<view class="iconfont icon-weixin3"></view>
				<view class="">{{$t(`发送给朋友`)}}</view>
			</button>
			<!-- #endif -->
			<!-- #ifdef MP -->
			<!-- <button class="item" open-type="share" hover-class="none" @click="goFriend">
				<view class="iconfont icon-weixin3"></view>
				<view class="">{{$t(`发送给朋友`)}}</view>
			</button> -->
			<!-- #endif -->
			<!-- #ifdef H5  -->
			
			<!-- #endif -->
			<!-- #ifdef APP-PLUS -->
			<view class="item" @click="appShare('WXSceneSession')">
				<view class="iconfont icon-weixin3"></view>
				<view class="">{{$t(`微信好友`)}}</view>
			</view>
			<view class="item" @click="appShare('WXSenceTimeline')">
				<view class="iconfont icon-pengyouquan"></view>
				<view class="">{{$t(`微信朋友圈`)}}</view>
			</view>
			<!-- #endif -->
			<button class="item" hover-class="none" @click="goPoster">
				<view class="iconfont icon-haibao"></view>
				<view class="">{{$t(`生成海报`)}}</view>
			</button>
		</view>
		<view class="mask" v-if="posters" @click="listenerActionClose"></view>
		<view class="poster-pop" v-if="posterImageStatus">
			<image src="@/static/images/poster-close.png" class="close" @click="posterImageClose">
			</image>
			<image :src="posterImage"></image>
			<!-- #ifndef H5  -->
			<view class="save-poster" @click="savePosterPath">{{$t(`保存到手机`)}}</view>
			<!-- #endif -->
			<!-- #ifdef H5 -->
			<view class="keep">{{$t(`长按图片可以保存到手机`)}}</view>
			<!-- #endif -->
		</view>
		<view class="mask" v-if="posterImageStatus"></view>
		<canvas class="canvas" canvas-id="myCanvas" v-if="canvasStatus"></canvas>
		<!-- 发送给朋友图片 -->
		<view class="share-box" v-if="H5ShareBox">
			<image :src="imgHost + '/statics/images/share-info.png'" @click="H5ShareBox = false"></image>
		</view>
	</view>
</template>

<script>
	import {
		getProductslist
	} from '@/api/store.js';
	import {
		getCustomer
	} from '@/utils/index.js'
	import colors from "@/mixins/color";
	import {
		sharePoster
	} from "@/mixins/sharePoster";
	import {
		mapGetters
	} from "vuex";
	import {
		toLogin
	} from "@/libs/login.js";
	import {
		getUserInfo,
		userShare
	} from "@/api/user.js";
	import {
		HTTP_REQUEST_URL
	} from '@/config/app';
	import {
		getProductDetail,
		getProductCode,
		collectAdd,
		collectDel,
		postCartAdd,
	} from "@/api/store.js";
	export default {
		name: 'goodList',
		props: {
			dataConfig: {
				type: Object,
				default: () => {}
			},
			isSortType: {
				type: String | Number,
				default: 0
			}
		},
		mixins: [colors, sharePoster],
		data() {
			return {
				imgHost: HTTP_REQUEST_URL,
				tempArr: [],
				mbConfig: this.dataConfig.mbConfig.val,
				numConfig: this.dataConfig.numConfig.val,
				themeColor: this.dataConfig.themeColor.color[0].item,
				itemStyle: this.dataConfig.itemStyle.type,
				sortType: this.dataConfig.goodsSort.type,
				type: this.dataConfig.tabConfig.tabVal || 0,
				selectId: this.dataConfig.selectConfig.activeValue,
				productIds: this.dataConfig.goodsList.ids || [],
				opriceShow: this.dataConfig.opriceShow.val, //商品原价
				priceShow: this.dataConfig.priceShow.val, //商品价格
				titleShow: this.dataConfig.titleShow.val, //商品名称
				couponShow: this.dataConfig.couponShow.val, //商品优惠券
				prConfig: this.dataConfig.prConfig.val, //左右边距
				bgStyle: this.dataConfig.bgStyle.type, //背景样式
				conStyle: this.dataConfig.conStyle.type, //内容样式
				fontColor: this.dataConfig.fontColor.color[0].item,
				labelColor: this.dataConfig.labelColor.color[0].item,
				posters: false,
				weixinStatus: false,
				storeInfo: {},
				posterImageStatus: false,
				canvasStatus: false, //海报绘图标签
				H5ShareBox: false, //公众号分享图片
				posterImage: "", //海报路径
			};
		},
		created() {},
		mounted() {
			this.productslist();
		},
		computed: mapGetters(["isLogin"]),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV == true) {
						this.downloadFilePromotionCode();
					}
				},
				deep: true,
			},

		},
		methods: {
			// 分享关闭
			listenerActionClose: function() {
				this.posters = false;
				this.posterImageStatus = false;
			},
			stop() {
				return true;
			},
			productslist() {
				let limit = this.$config.LIMIT;
				let data = {};
				if (this.type == 1) {
					data = {
						ids: this.productIds.join(','),
					};
				} else {
					data = {
						priceOrder: this.sortType == 2 ? 'desc' : '',
						salesOrder: this.sortType == 1 ? 'desc' : '',
						selectId: this.selectId[this.selectId.length - 1] || 0,
						limit: this.numConfig
					};
				}
				getProductslist(data).then(res => {
					this.tempArr = res.data;
				});
			},
			goDetail(item) {
				this.$emit('detail', item);
			},
			goUrl(url){
				uni.navigateTo({
					url:url
				})
			},
			/**
			 * 分享打开
			 *
			 */
			listenerActionSheet(item) {
				let temp = JSON.parse(JSON.stringify(item));
				temp['sys_share'] = true;
				this.$emit('detail', temp);
				return false;
				let that = this;
				if (this.isLogin === false) {
					toLogin();
				} else {
					console.log(this.storeInfo);
					getProductDetail(item.id)
						.then((res) => {
							that.storeInfo = res.data.storeInfo;
							
						})
					
					
					setTimeout(function(){
						that.ShareInfo();
					},1000);
					setTimeout(function(){
						that.getImageBase64();
					},2000);
					setTimeout(function(){
						that.downloadFilestoreImage();
					},3000);
					
					
					
					
					
					
					setTimeout(function(){
						if (that.posterImage) {
							that.posters = true;
							return
						}
						// #ifdef H5
						if (that.$wechat.isWeixin() === true) {
							that.weixinStatus = true;
						}
						
						that.downloadFilePromotionCode();
						// #endif
						// #ifdef MP
						// this.downloadFilePromotionCode();
						// #endif
						// #ifdef APP-PLUS
						// if (this.PromotionCode.indexOf("http") == 0) {
						// 	// this.downloadFilePromotionCode();
						
						// }
						// #endif
						
						that.posters = true;
					},4000)
					
					
				}
			},
			ShareInfo() {
				let data = this.storeInfo;
				let href = location.href;
				if (this.$wechat.isWeixin()) {
					getUserInfo().then((res) => {
						href =
							href.indexOf("?") === -1 ?
							href + "?spread=" + res.data.uid :
							updateURLParameter(href, 'spread', res.data.uid);
						let configAppMessage = {
							desc: data.store_info,
							title: data.store_name,
							link: href,
							imgUrl: data.image,
						};
						this.$wechat
							.wechatEvevt(
								[
									"updateAppMessageShareData",
									"updateTimelineShareData",
									"onMenuShareAppMessage",
									"onMenuShareTimeline",
								],
								configAppMessage
							)
							.then((res) => {})
							.catch((err) => {});
					});
				}
			},
			goCustomer() {
				getCustomer(`/pages/extension/customer_list/chat?productId=${this.ids}`)
			},

		}
	};
</script>

<style lang="scss">
	.xiaoliang {
		font-size: 28rpx;
		font-family: Source Han Sans CN-Regular, Source Han Sans CN;
		font-weight: 400;
		color: #666666;
		line-height: 33rpx;
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		background-color: #666666;
	}

	.listBig {
		padding: 0px 12rpx 12rpx 12rpx;

		.borderRadius15 {
			image {
				border-radius: 20rpx 20rpx 0 0;
			}
		}

		.itemBig {
			width: 100%;
			margin-top: 20rpx;
			background-color: #fff;
			padding-bottom: 15rpx;

			.img-box {
				width: 100%;
				height: 887.5rpx;
				position: relative;

				.pictrue_log_big {
					border-radius: 20rpx 0 20rpx 0;
				}

				image {
					width: 100%;
					height: 100%;
				}
			}

			.name {
				font-size: 28rpx;
				font-weight: bold;
				margin-top: 16rpx;
				padding: 0 8px;
				font-size: 36rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #333333;
				line-height: 42rpx;
				color: #333333;

				.coupon {
					display: inline-block;
					text-align: center;
					width: 32rpx;
					border-radius: 4rpx;
					font-size: 20rpx;
					font-weight: normal;
					margin-right: 10rpx;
				}
			}

			.price {
				font-weight: bold;
				font-size: 12px;
				margin-top: 10rpx;
				padding: 0 8px;

				.num {
					font-size: 32rpx;
					margin-right: 10rpx;
				}

				.old-price {
					color: #aaa;
					font-weight: normal;
					text-decoration: line-through;
				}
			}
		}
	}

	.index-product-wrapper {

		.list-box {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			padding: 20rpx 20rpx 0;

			.item {
				width: 345rpx;
				margin-bottom: 20rpx;
				background-color: #fff;
				overflow: hidden;
				position: relative;

				&.on {
					border-radius: 0;
				}

				.pictrue {
					width: 347rpx;
					height: 347rpx;
				}

				.pictrue_log {
					width: 92rpx;
					height: 44rpx;
					font-size: 26rpx;
					line-height: 44rpx;
					border-radius: 0 0 20rpx 0 !important;
				}

				image {
					// height: 346rpx;
					// width: 347rpx;
					// height: 347rpx;
					width: 100%;
					height: 100%;
					display: block;
				}

				.text-info {
					padding: 10rpx 20rpx 15rpx;

					.title {
						color: #222222;
					}

					.old-price {
						margin-top: 4rpx;
						font-size: 20rpx;
						color: #aaaaaa;
						text-decoration: line-through;

						text {
							margin-right: 2px;
							font-size: 20rpx;
						}
					}

					.price {
						display: flex;
						align-items: flex-end;
						font-size: 36rpx;
						font-weight: 550;

						text {
							padding-bottom: 4rpx;
							font-size: 26rpx;
							font-weight: normal;
						}

						.txt {
							display: flex;
							align-items: center;
							justify-content: center;
							width: 28rpx;
							height: 28rpx;
							margin-left: 15rpx;
							margin-bottom: 10rpx;
							border-radius: 4rpx;
							font-size: 20rpx;
							font-weight: normal;

							&.on {
								margin-left: 0;
							}
						}
					}
				}
			}

			&.on {
				display: flex;
			}

			&.listA {
				.item {
					display: flex;
					width: 100%;

					.pictrue {
						width: 220rpx !important;
						height: 220rpx !important;
					}

					.text-info {
						// width: 490rpx;
						flex: 1
					}
				}
			}

			&.listC {
				.item {
					width: 48.5%;
				}

				.pictrue {
					width: 100%;
					height: 345rpx;
				}
			}

			&.listB {
				justify-content: inherit;

				.item {
					width: 31.6%;
					margin-right: 16rpx;

					.pictrue {
						width: 100%;
						height: 220rpx;
					}

					&:nth-child(3n) {
						margin-right: 0;
					}
				}
			}
		}
	}

	.generate-posters {
		width: 100%;
		height: 170rpx;
		background-color: #fff;
		position: fixed;
		left: 0;
		bottom: 100rpx;
		z-index: 388;
		transform: translate3d(0, 100%, 0);
		transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
		border-top: 1rpx solid #eee;
	}

	.generate-posters.on {
		transform: translate3d(0, 0, 0);
	}

	.generate-posters .item {
		flex: 1;
		text-align: center;
		font-size: 30rpx;
	}

	.generate-posters .item .iconfont {
		font-size: 80rpx;
		color: #5eae72;
	}

	.generate-posters .item .iconfont.icon-haibao {
		color: #5391f1;
	}

	.generate-posters .item .iconfont.icon-haowuquan1 {
		color: #ff954d;
	}
</style>